﻿using System;
using System.Text;
using SimpleSocket.Protocols;

namespace ClientDemo
{
    internal class Program
    {
        class SocketClient : SimpleSocket.Client
        {
            public SocketClient(IProtocol protocol) : base(protocol)
            {
                
            }

            protected override void OnConnectionChanged(string remote, bool success)
            {
                base.OnConnectionChanged(remote, success);
                if (success)
                {
                    Console.WriteLine("连接成功");
                    BeginReceive();
                }
                else
                    Console.WriteLine("连接断开");
            }

            protected override void OnReceiveMessage(string remote, byte[] data)
            {
                base.OnReceiveMessage(remote, data);
                Console.WriteLine($"接收消息：{Encoding.UTF8.GetString(data)}");
            }

            protected override void OnSendDataCallback(string remote, byte[] data, bool success)
            {
                base.OnSendDataCallback(remote, data, success);
                Console.WriteLine($"消息发送成功");
            }
        }
        
        public static void Main(string[] args)
        {
            var client = new SocketClient(null);
            client.AutoReconnect = true;
            client.Connection("127.0.0.1",2242);
            Console.ReadKey();
        }
    }
}